package weaver.interfaces.zhlx.duss.action.faemodule.pdm;

import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.interfaces.zhlx.duss.utils.PdmUtil;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2023-11-27
 * @Description: 03 COQC Management 流程调用COQC Catalog No接口
 * @ModifyLog:
 **/
public class WeaCOQCManagementAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String src = requestInfo.getRequestManager().getSrc();
        writeLog(">>>>>WeaCOQCManagementAction>>>>>requestid=" + requestid);
        try {
            String message = "调用PDM系统接口返回:";
            JSONObject paramsJson = new JSONObject();
            JSONObject hearderJson = new JSONObject();
            hearderJson.put("TIMESTAMP", System.currentTimeMillis());
            hearderJson.put("INTERFACEID", "EC-PDM-03");
            hearderJson.put("FLOWNUMBER", requestid);
            paramsJson.put("header", hearderJson);
            RecordSet rs = new RecordSet();
            rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
            rs.next();
            String coqcbh = Util.null2String(rs.getString("coqcbh"));
            String coqcformatname3 = Util.null2String(rs.getString("coqcformatname3"));
            String coqcformatname4 = Util.null2String(rs.getString("coqcformatname4"));
            String coqccreationtype = Util.null2String(rs.getString("coqccreationtype"));
			String qy = Util.null2String(rs.getString("qy"));
            if ("1".equals(coqccreationtype) && "8".equals(qy)) {
                JSONObject dataJson = new JSONObject();
                dataJson.put("ITEMNUMBER", coqcbh);
                dataJson.put("CQCFMN", coqcformatname3);
                dataJson.put("CQCFMN2", coqcformatname4);
                paramsJson.put("data", dataJson);
                writeLog(">>>>>WeaCOQCManagementAction>>>>>paramsJson=" + paramsJson);
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("jkdymc", "WeaCOQCManagementAction");
                dataMap.put("lcid", requestid);
                dataMap.put("dylc", requestid);
                dataMap.put("cz", src);
                JSONObject resultJson = PdmUtil.coqcCatalogNo(paramsJson, dataMap);
                writeLog(">>>>>WeaCOQCManagementAction>>>>>resultJson=" + resultJson);
                String code = Util.null2String(resultJson.getString("code"));
                if ("success".equals(code)) {
                    JSONObject retrundataJson = JSONObject.parseObject(resultJson.getString("data"));
                    String status = Util.null2String(retrundataJson.getString("status"));
                    if (!"200".equals(status)) {
                        message += Util.null2String(retrundataJson.getString("message"));
                        requestInfo.getRequestManager().setMessageid("111111");
                        requestInfo.getRequestManager().setMessagecontent(message);
                        return Action.FAILURE_AND_CONTINUE;
                    }
                } else {
                    message += Util.null2String(resultJson.getString("message"));
                    requestInfo.getRequestManager().setMessageid("111111");
                    requestInfo.getRequestManager().setMessagecontent(message);
                    return Action.FAILURE_AND_CONTINUE;
                }
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口处理异常,请联系管理员");
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}